//
//  DDMyQuestionDetailViewController.m
//  dingdang
//
//  Created by Chen Jing on 15-7-26.
//  Copyright (c) 2015年 阮 沧晖. All rights reserved.
//

#import "DDMyQuestionDetailViewController.h"
#import "DDMyQuestionDetailCollectionViewCell.h"
#import "MJRefresh.h"
#import "DDMyQuestionDetailTempViewController.h"
#import "DDShare.h"
#import "DDShareViewController.h"
#import "DDTypeDefine.h"

@interface DDMyQuestionDetailViewController ()<UIScrollViewDelegate>{
    NSInteger currentPage;
    NSInteger totalPage;
}
@property (weak, nonatomic) IBOutlet UIView *contentOfMain;
@property (weak, nonatomic) IBOutlet UILabel *label_flag;

@property (weak, nonatomic) IBOutlet UIScrollView *myScrollView;
@end

@implementation DDMyQuestionDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    NSInteger elementCount = self.info_element.info_questions.count;
//    self.myScrollView.contentSize = CGSizeMake(self.view.frame.size.width * elementCount, self.contentOfMain.frame.size.height - 50);
//    
//    for (int i = 0; i < self.info_element.info_questions.count; i++) {
//        DDModelMyQuetionsListElement_answerInfo * detailInfo = self.info_element.info_questions[i];
//        DDMyQuestionDetailTempViewController * tempVC = [[DDMyQuestionDetailTempViewController alloc]init];
//        if (self.info_element.info_type.integerValue == DDType_question_questionPublishType_Reward) {
//            tempVC.isReward = YES;
//        }else{
//            tempVC.isReward = NO;
//        }
//        
//        [self addChildViewController:tempVC];
//        tempVC.view.frame = CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.myScrollView.frame.size.height);
//        tempVC.info_element = self.info_element;
//        tempVC.info_detailInfo = detailInfo;
//        [self.myScrollView addSubview:tempVC.view];
//    }
//    currentPage = 0;
//    totalPage = elementCount;
//    self.label_flag.text = [NSString stringWithFormat:@"%@/%@",[NSNumber numberWithInteger:currentPage + 1],[NSNumber numberWithInteger:totalPage]];
    
    
    
    [self createUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//ruanch bug - 标签更新显示
-(void)viewWillAppear:(BOOL)animated{
    NSInteger elementCount = self.info_element.info_questions.count;
    self.myScrollView.contentSize = CGSizeMake(self.view.frame.size.width * elementCount, self.contentOfMain.frame.size.height - 50);

    for (int i = 0; i < self.info_element.info_questions.count; i++) {
        DDModelMyQuetionsListElement_answerInfo * detailInfo = self.info_element.info_questions[i];
        DDMyQuestionDetailTempViewController * tempVC = [[DDMyQuestionDetailTempViewController alloc]init];
        if (self.info_element.info_type.integerValue == DDType_question_questionPublishType_Reward) {
            tempVC.isReward = YES;
        }else{
            tempVC.isReward = NO;
        }

        [self addChildViewController:tempVC];
        tempVC.view.frame = CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.myScrollView.frame.size.height);
        tempVC.info_element = self.info_element;
        tempVC.info_detailInfo = detailInfo;
        [self.myScrollView addSubview:tempVC.view];
    }
    currentPage = 0;
    totalPage = elementCount;
    self.label_flag.text = [NSString stringWithFormat:@"%@/%@",[NSNumber numberWithInteger:currentPage + 1],[NSNumber numberWithInteger:totalPage]];

}

-(void)createUI{

    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;

    //自定义TAB BAR UI
    [self addNavigatorTitle:@"答题详情" parent:self.view];
    self.barViewControl.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_Background"]];

    [self AddLeftBtnAction:@"" normal:@"top_返回" selected:@"top_返回" action:^{
        [self.navigationController popViewControllerAnimated:YES];
    }];





    [self AddRightBtnAction:@"分享" normal:@"" selected:@"" action:^{

        [DDShareViewController  showShareWithController:self];
    }];

}



-(void)createData{

}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger page = scrollView.contentOffset.x / self.view.frame.size.width;
    if (page != currentPage) {
        currentPage = page;
        self.label_flag.text = [NSString stringWithFormat:@"%@/%@",[NSNumber numberWithInteger:currentPage + 1],[NSNumber numberWithInteger:totalPage]];
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
